<?php
namespace 	Common\Model;
use Common\Model\CommonModel;
class OrderModel extends CommonModel
{
	
	protected $_validate = array(
			//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
			array('name', 'require', '联系人不能为空！'),
			array('tel', 'require', '联系电话不能为空！'),
			array('address', 'require', '地址不能为空！'),
			array('num', 'number', '数量格式有误！'),

	);
	
	//用于获取时间，格式为2012-02-03 12:12:12,注意,方法不能为private
protected $_auto = array ( 
		array('inputtime','time',1,'function'),
		
		
);


	function get_sum_price($order_sn,$pay_type){


		$info=$this->where(array("order_sn"=>$order_sn))->find();


		if($pay_type=="weixin"){

			$bi=C("WX_ZK");
		}
		elseif($pay_type=="qianbao"){

			$bi=C("QB_ZK");

		}
		else{


			$bi=1;

		}

		return round($info["price_sum"]*$bi/10,2);





	}


	public function jiesuan($pay_type,$order_sn,$sum_price,$uid){




		$result=array(

			"status"=>2,
			"pay_type"=>$pay_type,


		);

		if($pay_type=="qianbao")
		{


			$s=D("Users")->xiaofei($uid,$sum_price);

			if(!$s){
				return false;

			}else{


			}




		}


		$this->where(array("order_sn"=>$order_sn))->save($result);

		return true;








	}



	public function xiaoshou_jishu($order_sn){


		$ps=M("OrderInfo")->where(array("order_sn"=>$order_sn))->select();


		foreach($ps as $k=>$v){


			M("Product")->where(array("id"=>$v["product_id"]))->setInc('xiaoshou',$v["num"]); // 用户的积分加3


		}





	}

}

?>